﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiMovAviFilesGridWrapper
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using C1.Win.C1FlexGrid;
using C1.Win.C1FlexGrid.Util.BaseControls;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui48;


namespace DnProcessSimulateCommands;

internal class CUiMovAviFilesGridWrapper : TxFlexGridExtension
{
  private const int ATTACHMENT_NAME_COL_NUM = 0;
  private TxFileAttachment m_selectedAttribute;

  public TxFileAttachment SelectedRowData => this.m_selectedAttribute;

  public CUiMovAviFilesGridWrapper() => this.InitializeComponent();

  public void InitializeAviFilesGrid(CApMovMovieManagerNodeData nodeData)
  {
    OrderedDictionary attachmentsPathAndDate = nodeData.AttachmentsPathAndDate;
    int num = 1;
    ((RowColCollection) ((C1FlexGridBase) this).Rows).Count = num;
    foreach (DictionaryEntry dictionaryEntry in attachmentsPathAndDate)
    {
      ((C1FlexGridBase) this).Rows.InsertNode(num, 0);
      ((C1FlexGridBase) this).Rows[num].Node.Key = dictionaryEntry.Key;
      ((C1FlexGridBase) this)[num, 0] = (object) ((TxFileAttachment) dictionaryEntry.Key).Name;
      ++num;
    }
    this.AutoSiezeName();
    if (attachmentsPathAndDate.Count <= 0)
      return;
    ((C1FlexGridBase) this).Select(1, 0);
  }

  public void ClearAVIFIlesSelection()
  {
    if (((C1FlexGridBase) this).RowSel <= 0)
      return;
    ((ScrollableControl) this).BeginUpdate();
    ((C1FlexGridBase) this).Select(-1, -1);
    this.AutoSiezeName();
    ((ScrollableControl) this).EndUpdate();
  }

  private void AutoSiezeName()
  {
    ((C1FlexGridBase) this).AutoSizeCols(0, ((RowColCollection) ((C1FlexGridBase) this).Cols).Count - 1, 1);
    ((C1FlexGridBase) this).AutoSizeRows();
  }

  public void ClearAVIFIlesData() => ((RowColCollection) ((C1FlexGridBase) this).Rows).Count = 1;

  protected virtual void ClearAllMarked() => this.m_selectedAttribute = (TxFileAttachment) null;

  protected virtual void MarkAllSelected()
  {
    foreach (Row row in (IEnumerable) ((C1FlexGridBase) this).Rows.Selected)
      this.m_selectedAttribute = row.Node.Key as TxFileAttachment;
  }

  protected virtual void SetupCustomStyles() => ((TxFlexGrid) this).SetupCustomStyles();

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiMovAviFilesGridWrapper));
    ((ISupportInitialize) this).BeginInit();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this, "$this");
    ((C1FlexGridBase) this).SelectionMode = (SelectionModeEnum) 7;
    ((C1FlexGridBase) this).SelChange += new EventHandler(this.aviFilesFlexGrid_SelChange);
    ((ISupportInitialize) this).EndInit();
    ((Control) this).ResumeLayout(false);
  }

  private void aviFilesFlexGrid_SelChange(object sender, EventArgs e)
  {
    int rowSel = ((C1FlexGridBase) this).RowSel;
    this.m_selectedAttribute = (TxFileAttachment) null;
    if (((RowColCollection) ((C1FlexGridBase) this).Rows).Count <= 1)
      return;
    if (rowSel > 0)
    {
      RowCollection rows = ((C1FlexGridBase) this).Rows;
      this.m_selectedAttribute = rows[rowSel].Node.Key as TxFileAttachment;
      ((RowCol) rows[rowSel]).Selected = true;
    }
    else
    {
      if (!((RowCol) ((C1FlexGridBase) this).Rows[1]).Selected && ((RowCol) ((C1FlexGridBase) this).Rows[1]).Style != ((C1FlexGridBase) this).Styles["Highlight"])
        return;
      this.m_selectedAttribute = ((C1FlexGridBase) this).Rows[1].Node.Key as TxFileAttachment;
    }
  }
}
